import { loadSync } from '@grpc/proto-loader'
import { PROTO_PATH } from '@scretConfig'
import { BaseService } from '@services/BaseService'
import { credentials, loadPackageDefinition, PackageDefinition } from 'grpc'
import { Server } from '../../server'
import { WxProtoMessage } from './rpcMessageModel'

export class GRPCService extends BaseService {

  private packageDefinition: PackageDefinition

  constructor(server: Server) {
    super(server)
    this.packageDefinition = loadSync(PROTO_PATH, {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
    })

    let message = loadPackageDefinition(this.packageDefinition).message as WxProtoMessage
    const client = new message.HelloService('localhost:50001', credentials.createInsecure())

    client.SayHello({ message: 'world' }, (_err: any, _response: any) => {
      console.log(1)
    })
    this.init()
  }

  private init() {

  }
}
